﻿using System.Collections.Generic;

namespace Xwltz.Standard.Cloud
{
    public class CosService
    {
        private const string CosapiCgiUrl = "http://sh.file.myqcloud.com/files/v2/";
        //文件大于8M时采用分片上传,小于等于8M时采用单文件上传
        private const int SliceUploadFileSize = 8 * 1024 * 1024;
        //用户计算用户签名超时时间
        private const int SignExpiredTime = 180;
        //HTTP请求超时时间
        private const int HttpTimeoutTime = 60;
        private readonly int _appId;
        private readonly string _secretId;
        private readonly string _secretKey;
        private readonly int _timeOut;


        /// <summary>
        /// CosCloud 构造方法
        /// </summary>
        /// <param name="appId">授权appid</param>
        /// <param name="secretId">授权secret id</param>
        /// <param name="secretKey">授权secret key</param>
        /// <param name="timeOut">网络超时,默认60秒</param>
        public CosService(int appId, string secretId, string secretKey, int timeOut = HttpTimeoutTime)
        {
            _appId = appId;
            _secretId = secretId;
            _secretKey = secretKey;
            _timeOut = timeOut * 1000;

        }

        /// <summary>
        /// 删除文件夹
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件夹路径</param>
        /// <returns></returns>
        public string DeleteFolder(string bucketName, string remotePath)
        {
            return "";
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件路径</param>
        /// <returns></returns>
        public string DeleteFile(string bucketName, string remotePath)
        {
            return "";
        }

        /// <summary>
        /// 获取文件夹信息
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件夹路径</param>
        /// <returns></returns>
        public string GetFolderStat(string bucketName, string remotePath)
        {
            return "";
        }

        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件路径</param>
        /// <returns></returns>
        public string GetFileStat(string bucketName, string remotePath)
        {
            return "";
        }

        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件夹路径</param>
        /// <param name="parameterDic">参数Dictionary</param>
        /// 包含如下可选参数：biz_attr:目录属性
        /// <returns></returns>
        public string CreateFolder(string bucketName, string remotePath, Dictionary<string, string> parameterDic = null)
        {
            return "";
        }

        /// <summary>
        /// 文件上传
        /// 说明: 根据文件大小判断使用单文件上传还是分片上传,当文件大于8M时,内部会进行分片上传,可以携带分片大小sliceSize
        /// 其中分片上传使用SliceUploadInit SliceUploadData SliceUploadFinihs
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件路径</param>
        /// <param name="localPath">本地文件路径</param>
        /// <param name="parameterDic">参数Dictionary</param>
        /// 包含如下可选参数
        /// bizAttribute：文件属性
        /// insertOnly： 0:同名文件覆盖, 1:同名文件不覆盖,默认1
        /// sliceSize: 分片大小，可选取值为:64*1024 512*1024，1*1024*1024，2*1024*1024，3*1024*1024
        /// <returns></returns>
        public string UploadFile(string bucketName, string remotePath, string localPath, Dictionary<string, string> parameterDic = null)
        {
            return "";
        }

        /// <summary>
        /// 单个文件上传
        /// </summary>
        /// <param name="bucketName">bucket名称</param>
        /// <param name="remotePath">远程文件路径</param>
        /// <param name="localPath">本地文件路径</param>
        /// <param name="bizAttribute">biz_attr属性</param>
        /// <param name="insertOnly">同名文件是否覆盖</param>
        /// <returns></returns>
        public string Upload(string bucketName, string remotePath, string localPath, string bizAttribute = "", int insertOnly = 1)
        {
            return "";
        }
    }
}
